import weui from 'weui.js'

const CheckSubmit = (name, phone, address) => {
  const checkName = /^[\u4e00-\u9fa5]{2,4}$/ // 验证中文名字
  const checkPhone = /^[1][3|4|5|6|7|8|9]\d{9}$/ // 验证手机号
  const checkTel = /^[0]\d{10,11}$/  // 验证电话

  if (!name) {
    return [0, '收件人姓名不能为空']
  } else if (!checkName.test(name)) {
    return [0, '请输入正确的姓名'];
  } else if (!phone) {
    return [0, '收件人电话不能为空'];
  } else if (phone) {
    const phoneFirst = phone.substring(0, 1);

    return phoneFirst == 1 && !checkPhone.test(phone) ? [0, '请输入正确的手机号码'] : ((phoneFirst != 1 && !checkTel.test(phone)) ? [0, '请输入正确的固话号码'] : (!address ? [0, '请输入详细地址'] : [1, '验证成功']));
  }
}

export default CheckSubmit;